﻿using System;

namespace MapleLeaf.Pay {

    public static class TimeStamp {

        public static long Now => DateTime.Now.GetTimeStamp();


        public static long GetTimeStamp(this DateTime dt) {
            return (long)(dt.ToUniversalTime() - UnixEpoch).TotalMilliseconds;
        }


        public static long? GetTimeStamp(this DateTime? dt) {
            long? result = dt != null ? new long?(dt.Value.GetTimeStamp()) : null;
            return result;
        }


        public static DateTime GetDateTime(long ts) {

            return UnixEpoch.AddSeconds(ts).ToLocalTime();
        }


        static TimeStamp() {
            UnixEpoch = new DateTime(621355968000000000);
        }

        public static readonly DateTime UnixEpoch;
    }
}
